package com.javaear.beangenerator.tools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * String commons constans or process action
 *
 * @author aooer
 */
public class StringUtils {

    /**
     * Beaner prefix
     */
    public static final String PREFIX_SPACE = "    ";

    /**
     * line
     */
    public static final String LINE = System.getProperty("line.separator");

    /**
     * default create bean path
     */
    public static final String DEFAULT_DEST_DIR = System.getProperty("user.dir");

    /**
     * upper first char
     *
     * @param sourceStr string
     * @return targetStr
     */
    public static String upperCaseFirstChar(String sourceStr) {
        return String.valueOf(Character.toUpperCase(sourceStr.charAt(0))) + sourceStr.substring(1);
    }

    /**
     * lower first char
     *
     * @param sourceStr string
     * @return targetStr
     */
    public static String lowerCaseFirstChar(String sourceStr) {
        return String.valueOf(Character.toLowerCase(sourceStr.charAt(0))) + sourceStr.substring(1);
    }

    /**
     * check is empty
     *
     * @param sourceStr source
     * @return is empty or not
     */
    public static boolean isEmpty(String sourceStr) {
        return sourceStr == null || "".equals(sourceStr);
    }

    /**
     * camel and underline convent
     *
     * @param sourceStr source
     * @return targetString
     */
    public static String camelCaseUnderline(String sourceStr) {
        Pattern pattern = Pattern.compile("_[a-z]");
        Matcher matcher = pattern.matcher(sourceStr);
        StringBuffer sb = new StringBuffer();
        while (matcher.find())
            matcher.appendReplacement(sb, matcher.group().substring(1, 2).toUpperCase());
        matcher.appendTail(sb);
        return sb.toString();
    }


}
